//
//  Comment.m
//  XPhoto
//
//  Created by baboy on 2019/7/4.
//  Copyright © 2019 baboy. All rights reserved.
//

#import "Comment.h"
#import <BKKit/BKApi.h>
#import "HttpResponse.h"

@implementation Comment

+ (id)add:(Comment*)comment callback:(nullable void (^)(id _Nonnull task, id _Nullable json,  NSError * _Nullable error))callback{
    id task = [BKApi request: API_COMMENT_ADD
                parameters: comment
                  callback:^(id  _Nonnull task, id  _Nullable json, NSError * _Nullable error) {
                      DLOG(@"%@",json);
                      DLOG(@"%@",error);
                      HttpResponse *response = [HttpResponse responseWithDictionary:json];
                      if (!error && ![response isSuccess]) {
                          error = [NSError errorWithDomain:HttpRequestDomain code:response.status userInfo:@{NSLocalizedDescriptionKey:response.msg}];
                      }
                      callback(task, response.data,error);
                  }];
    return task;
}

+ (id)searchWithArgs:(CommentSearchArgs *)args callback:(nullable void (^)(id _Nonnull task, id _Nullable json,  NSError * _Nullable error))callback{
    id task = [BKApi request:API_COMMENT_SEARCH
                parameters:args
                  callback:^(id  _Nonnull task, id  _Nullable json, NSError * _Nullable error) {
                      HttpResponse *response = [HttpResponse responseWithDictionary:json dataItemClass:[Comment class]];
                      if (!error && ![response isSuccess]) {
                          error = [NSError errorWithDomain:HttpRequestDomain code:response.status userInfo:@{NSLocalizedDescriptionKey:response.msg}];
                      }
                      DLOG(@"%@",json);
                      DLOG(@"%@",error);
                      if (callback) {
                          callback(task, response.data,error);
                      }
                  }];
    return task;
}
@end

@implementation CommentSearchArgs
@end
